import "../styles/globals.css";
import type { AppProps } from "next/app";
import type { GetServerSidePropsContext } from "next";
import { NextUIProvider } from "@nextui-org/system";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { useRouter } from "next/navigation";
import { Layout } from "@/components/layout/layout";
import { Provider as ReduxProvider } from "react-redux";
import store from "@/store";
// import "reflect-metadata";

function MyApp({ Component, pageProps }: AppProps) {
  const router = useRouter();
  return (
    <NextThemesProvider defaultTheme="system" attribute="class">
      <NextUIProvider navigate={router.push} className="config-center-app">
        <ReduxProvider store={store}>
          <Layout isBg={pageProps.isBg}>
            <Component {...pageProps} />
          </Layout>
        </ReduxProvider>
      </NextUIProvider>
    </NextThemesProvider>
  );
}

export function getServerSideProps(context: GetServerSidePropsContext) {
  const token = context.req.cookies["access_token"] ?? "";
  return {
    props: {
      token,
    },
  };
}
export default MyApp;
